$(document).ready(function() {

	$().invokeInplaceEditing();

});

$.fn.invokeInplaceEditing = function () {

		$(".edit_textinput").editInPlace({
			url: siteURL + "/epicentr/setfield/",
			params: "ajax=yes",
			success: function (html, element) {
				parts = element.attr('id').split('|');
				
				itemid = parts[0];
				type = parts[1];
				field = parts[2];
				
				lookingfor = 'ref-'+type+'-'+itemid+'-'+field;
				
				$('.'+lookingfor).text(html);
			}
		});
		
		$(".edit_dateinput").editInPlace({
			url: siteURL + "/epicentr/setfield/date/",
			params: "ajax=yes"
		});
		
		$(".edit_textarea").editInPlace({
			url: siteURL + "/epicentr/setfield",
			params: "ajax=yes",
			field_type: "textarea",
		    textarea_rows: "10",
		    textarea_cols: "35"
		});
		
		if (typeof(industry_select) == 'undefined') industry_select = '';
		$(".edit_industry").editInPlace({
			url: siteURL + "/epicentr/setfield/select/",
			params: "ajax=yes",
			field_type: "select",
			select_options: industry_select	
		});
		
		if (typeof(department_select) == 'undefined') department_select = '';
		$(".edit_departmentselect").editInPlace({
			url: siteURL + "/epicentr/setfield/departmentselect/",
			params: "ajax=yes",
			field_type: "select",
			select_options: department_select	
		});
		
		$(".edit_userlevel").editInPlace({
			url: siteURL + "/epicentr/setfield/userlevel/",
			params: "ajax=yes",
			field_type: "select",
			select_options: "Standard:standard,Admin:admin"	
		});
		
		if (typeof(supplier_select) == 'undefined') supplier_select = '';
		$(".edit_supplierselect").editInPlace({
			url: siteURL + "/epicentr/setfield/supplierselect/",
			params: "ajax=yes",
			field_type: "select",
			select_options: supplier_select	
		});
		
		if (typeof(contact_select) == 'undefined') contact_select = '';
		$(".edit_contactselect").editInPlace({
			url: siteURL + "/epicentr/setfield/contactselect/",
			params: "ajax=yes",
			field_type: "select",
			select_options: contact_select	
		});
		
		if (typeof(user_select) == 'undefined') user_select = '';
		$(".edit_userselect").editInPlace({
			url: siteURL + "/epicentr/setfield/userselect/",
			params: "ajax=yes",
			field_type: "select",
			select_options: user_select	
		});
		
		if (typeof(country_select) == 'undefined') country_select = '';
		$(".edit_countryselect").editInPlace({
			url: siteURL + "/epicentr/setfield/countryselect/",
			params: "ajax=yes",
			field_type: "select",
			select_options: country_select	
		});
		
		$(".edit_livestatus").editInPlace({
			url: siteURL + "/epicentr/setfield/livestatus/",
			params: "ajax=yes",
			field_type: "select",
			select_options: "Live:0,Archived:1"	
		});
		
		$(".edit_yesno").editInPlace({
			url: siteURL + "/epicentr/setfield/yesno/",
			params: "ajax=yes",
			field_type: "select",
			select_options: "Yes:1,No:0"	
		});
}